<? 
	include('base.php');
	User::protect();
	$section = 'band_members';
	include_class('band_members');
	include_class('m2');
	$editors = array('description');
	$bm = BandMember::get($_GET['id']);
	
	if (!db::isError($bm)) {
		$mi = MediaInstance::get($_GET['media_instance_id']);
		if (!db::isError($mi)) {
			$type = ($mi->getAreaID() == $bm->getAVAreaID()) ? "av" : "photos";
			switch($_GET['task']) {
				case 'update':
					$res = $mi->update($_POST, $bm);
					if (!db::isError($res)) {
						header('Location: band_member_media_edit.php?id=' . $_GET['id'] . '&media_instance_id=' . $_GET['media_instance_id']);
					}
					break;
				case 'deactivate':
					$res = $mi->deactivate($bm);
					if (!db::isError($res)) {
						header('Location: band_member_media_edit.php?id=' . $_GET['id'] . '&media_instance_id=' . $_GET['media_instance_id']);
					} 
					break;
				case 'activate':
					$res = $mi->activate($bm);
					if (!db::isError($res)) {
						header('Location: band_member_media_edit.php?id=' . $_GET['id'] . '&media_instance_id=' . $_GET['media_instance_id']);
					}
					break;
				case 'delete':
					$res = $mi->delete($bm);
					if (!db::isError($res)) {
						header('Location: band_member_media.php?id=' . $_GET['id'] . '&type=' . $type);
					}
					break;
			}
		}
	}
	
	
	$page_title = 'Edit Band Member Media';
	include('layout/header.php');

if (!db::isError($bm)) {

?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_members.php">Band Members&nbsp;&#62;</a>&nbsp;<a href="band_member_edit.php?id=<?=$_GET['id']?>">View/Edit Band Member&nbsp;&#62;</a>&nbsp;<a href="band_member_media.php?id=<?=$_GET['id']?>&amp;type=<?=$type?>">Media&nbsp;&#62;</a>&nbsp;Edit Media
</div>

<? 
	
	$canEdit = $bm->canEdit();
	if ($res) { // it's an error
		if (db::isError($res)) {
			$res->outputList();
		}
	}
	if (!db::isError($mi)) {
		if ($_GET['task'] == 'edit' && $canEdit) { 
		
			$exitURL = 'band_member_media_edit.php?id=' . $_GET['id'] . '&media_instance_id=' .  $_GET['media_instance_id'];
			include('layout/media_edit.php');				
			
			
		} else {
		
			$exitURL = 'band_member_media.php?id=' . $_GET['id'] . '&type=' . $type;
			include('layout/media_view.php'); 	
		
		}
	
	} else {
		
		$mi->outputDialog('Return to Band Members','band_member_edit.php?id=' . $_GET['id']);
		
	}
	
			
} else { ?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_members.php">Band Members&nbsp;&#62;</a>&nbsp;Invalid Entry
</div>

<?
	$bm->outputDialog('Return to Band Members','band_members.php','Please specify a valid band member ID.');

} ?>

<? include('layout/footer.php'); ?>
